"""
日程页面类
封装日程页面的元素定位器和操作方法
"""
from selenium.webdriver.common.by import By
from page.base_page import BasePage
from time import sleep


class SchedulePage(BasePage):
    # 日程页面相关路径
    url = "/index.php?m=calendar"

    # 定位器
    schedule_menu_locator = (By.CSS_SELECTOR,
                             "body > div.navbar.navbar-inverse.navbar-fixed-top > div > div > div.nav-collapse.collapse > ul:nth-child(1) > li:nth-child(6) > a")
    create_schedule_btn_locator = (By.CSS_SELECTOR, "body > div.container > div.row > div:nth-child(1) > div > a")
    subject_input_locator = (By.ID, "subject")
    save_btn_locator = (By.CSS_SELECTOR,
                        "body > div.container > div.row > div > form > table > tfoot > tr > td:nth-child(2) > input:nth-child(1)")
    all_schedule_btn_locator = (By.CSS_SELECTOR, "body > div.container > p > a.active")

    def click_schedule_menu(self):
        """点击日程菜单"""
        self.click(self.schedule_menu_locator)
        sleep(2)

    def click_create_schedule(self):
        """点击新建日程按钮"""
        self.click(self.create_schedule_btn_locator)
        sleep(2)

    def input_subject(self, content):
        """输入日程主题"""
        self.send_keys(self.subject_input_locator, content)
        sleep(1)

    def click_save(self):
        """点击保存按钮"""
        self.click(self.save_btn_locator)
        sleep(2)

    def click_all_schedule(self):
        """点击全部按钮"""
        self.click(self.all_schedule_btn_locator)
        sleep(2)

    def create_new_schedule(self, subject):
        """封装创建新日程的完整流程"""
        self.click_schedule_menu()
        self.click_create_schedule()
        self.input_subject(subject)
        self.click_save()
